<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>病床管理</title>
</head>
<body>
<style type="text/css">
	.box-ljw{
		border: 1px solid #A8A8A8;
   	 	padding: 0 10px;
   	 	border-radius: 5px;
	}
	.box-ljw i{
	    border-bottom: 1px solid #aaa;
	    display: inline-block;
	    width: 100px;
	    text-align: center;
	}
	.box-ljw .text-css{
		border: 0px;
	    border-bottom: 1px solid #aaa;
	    background: #dee;
	    text-align: center;
	    width: 80px;
	    height: 24px;
	    outline: none;
	    font-style: italic;
	   	font-weight: bold;
    	color: black;
	}
	#bedNameText{
		width: 120px;
	}
</style>
<script type="text/javascript">
$(function(){
	initBed("");//初始化床位的表格
	initExchange("");//初始化调整记录的表格
	
	//调整按钮
	$("#exBtn").click(function(){
		var row = $("#bedTable").datagrid("getSelected");
		var hid = $("input[name='hid']").val();
		var nowBed = $("#nowBid").combobox('getText');
		if(hid == null || hid == ""){
			return ;
		}
		var old = $("#oldBid").val();
		var now = $("#nowBid").combobox('getValue');
		$.ajax({
			url:'ljw-bed-exchange',
			data:{"hid":hid,"oldBid":old,"nowBid":now},
			async : false,
			success:function(data){
				//清除下拉框选中
				$("#nowBid").combobox('clear');
				setTimeout(function(){//延迟等表格刷新在赋值
					//重新赋值 
					$("#bedOldText").val(nowBed);
					$("#oldBid").val(now);
					$("#nowBid").combobox({
						url:'ljw-bed?did='+data,
						valueField:'bed_id',
						textField:'bed_number'
					});
				},500);
			}
		});
		//刷新表格
		$('#bedTable').datagrid('reload');
	});
	
	//搜索框事件
	$("#bedText").searchbox({
		searcher:function(value){
			initBed(value);
		},
	});
	
	//出院记录的搜索框
	$("#exchangeSear").searchbox({
		searcher:function(value){
			initExchange(value);
		}
	});
	
	//选项卡点击时刷新表格数据
	$("#bedTabs").tabs({
		onSelect:function(title){
			if(title=="调整记录"){
				$('#exchangeTable').datagrid('reload'); 
			}
		}
	}); 
	
	//新增床位按钮
	$("#addbedBtn").click(function(){
		$(".bedWin").window("open");
		$("#dep_bed").textbox("setValue","${user.departmentsPx.departmentsName }");
	})
	//新增床位确定按钮
	$("#bedOkBtn").click(function(){
		var bed = $("#bed_add").textbox("getValue");
		if($.trim(bed)==""){
			return;
		}
		$.post(
			"ljw-addBed",
			{"bed":bed},
			function(data){
				if(data="成功"){
					initBed("");
					$("#bed_add").textbox("setValue","");
					$(".bedWin").window("close");
				}
			}
		);
	});
	//取消
	$("#bedCancelBtn").click(function(){
		$(".bedWin").window("close");
	});
});

//调整记录的表格初始化
function initExchange(hid){
	$("#exchangeTable").datagrid({
		url:'ljw-exchange-record?hid='+hid,
		singleSelect:true,
		fitColumns:true,
		pagination:true,
	 	columns:[[
			{field:'hospital_id',title:'住 院 号',width:100,halign:'center'},
			{field:'patient_name',title:'姓 名',width:100,halign:'center'},
			{field:'patient_sex',title:'性 别',width:100,halign:'center'},
			{field:'exchange_ago',title:'原 床 位',width:150,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}		
			},
			{field:'exchange_now',title:'调 整 至',width:150,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}		
			},
			{field:'exchange_time',title:'调 整 时 间',width:200,align:'center',
				formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}	
			},
			{field:'exchange_name',title:'操 作 人',width:100,halign:'center'}
	    ]],
	});
}

/* 床位表格初始化 */
function initBed(hid){
	$("#bedTable").datagrid({
		url:"ljw-bed-all?hid="+hid+"&did="+ "${user.departmentsPx.departmentsId }" ,
		singleSelect:true,
		fitColumns:true,
		pagination:true,
	    pageSize:10,
	    pageList:[10,20],
	    columns:[[
			{field:'bed_number',title:'床 位',fixed:false,width:150,halign:'center',
				formatter:function(value,row,index){
					return value+"号床";
				}		
			},
			{field:'hospital_id',title:'住 院 号',fixed:false,width:100,halign:'center'},
			{field:'departments_id',hidden:true},
			{field:'patient_name',title:'姓 名',fixed:false,width:100,halign:'center'},
			{field:'patient_age',title:'年 龄',fixed:false,width:100,halign:'center'},
			{field:'patient_sex',title:'性 别',fixed:false,width:100,halign:'center'},
			{field:'departments_name',title:'科 室',fixed:false,width:100,halign:'center'}
	    ]],
	    onClickRow:function(index, row){
	    	$("input[name='hid']").val(row.hospital_id);
			$("#bedNameText").val(row.patient_name);
			$("#bedOldText").val(row.bed_number);
			$("#oldBid").val(row.bed_id);
			$("#nowBid").combobox({
				url:'ljw-bed?did='+row.departments_id,
				valueField:'bed_id',
				textField:'bed_number'
			});
	    }
	});
}
</script>
<div class="easyui-tabs" id="bedTabs" fit="true" style="user-select:none;">
	<div title="床位管理" >
		<div class="box-ljw" style="padding: 8px;background: #dee;border: 1px solid #A8A8A8;border-bottom: 0;">
			<div style="display: inline-block;">
				<input id="bedText" class="easyui-searchbox" style="width:160px;height:28px;padding-left:5px;"
							data-options="labelAlign:'right',prompt:'住院号/姓名查询'">
			</div>
			<span style="display: inline-block;margin-left: 20px;">
				姓名：<input id="bedNameText" class="text-css" disabled="disabled">
					<input name="hid" type="hidden" >
			</span>
			<span style="display: inline-block;margin-left: 20px;">
				现床位：<input name="exchangeAgo" id="bedOldText" class="text-css" disabled="disabled">
				<input id="oldBid" type="hidden" >
			</span>
			<select id="nowBid" name="exchangeNow" class="easyui-combobox" editable="false" panelHeight="auto"
					 	data-options="label:'调整至：',labelAlign:'right'" style="width:160px;cursor: pointer;">
			</select>	
			<a id="exBtn" class="easyui-linkbutton" style="padding:0 8px;margin-left: 30px;">确定调整</a>
		
			<a id="addbedBtn" class="easyui-linkbutton" style="padding:0 8px">新增床位</a>
	 		
		</div>
		<table id="bedTable" class="easyui-datagrid" style="height:390px">
		
		</table>
		
		<!-- 弹出层 -->
		<div class="easyui-window bedWin" title="新增床位"
		data-options="modal:true,collapsible:false,minimizable:false,
		maximizable:false,closed:true,draggable:false,shadow:true,resizable:false" style="padding:20px 40px">
			<form id="payForm" class="easyui-box" action="" method="post">
				<p>
					<input name="" id="dep_bed" editable="false" class="easyui-textbox" required="required"
					 data-options="label:'科      室：',labelAlign:'right',width:220" />
				</p>
				<p>
					<input name="" id="bed_add" class="easyui-textbox" required="required"
					 data-options="label:'床位号：',labelAlign:'right',width:220" />
				</p>
					
				<div style="margin: 0 auto;width:200px;text-align: center">
					<a id="bedOkBtn" class="easyui-linkbutton" style="padding:0 8px;margin-right: 50px;"> 确 定 </a>
					<a id="bedCancelBtn" class="easyui-linkbutton" style="padding:0 8px;"> 取 消 </a>
				</div>
			</form>
		</div>
		
		
	</div>
	
	<div title="调整记录" >
		<div class="box-ljw" style="padding: 8px;px;background: #dee;border: 1px solid #A8A8A8;border-bottom: 0;">
			<input id="exchangeSear" class="easyui-searchbox" style="width:200px;height:28px;padding-left:5px;"
				data-options="labelAlign:'right',prompt:'住院号/姓名查询'" >
		</div>
		<table id="exchangeTable" class="easyui-datagrid" style="height:390px">
		
		</table>
	</div>
	
</div>
</body>
</html>